package builders;

import org.joda.time.DateTime;

import users.Person;
import books.Book;
import books.Loan;

/**
 * Loan builder.
 */

public class LoanBuilder implements IBuilderExampler<Loan> {
    private Person loaner;

    private Book loanedBook;

    private DateTime start;

    private DateTime end;

    private boolean finished;

    public Person getLoaner() {
        return this.loaner;
    }

    public void setLoaner(final Person loaner) {
        this.loaner = loaner;
    }

    public Book getLoanedBook() {
        return this.loanedBook;
    }

    public void setLoanedBook(final Book loanedBook) {
        this.loanedBook = loanedBook;
    }

    public DateTime getStart() {
        return this.start;
    }

    public void setStart(final DateTime start) {
        this.start = start;
    }

    public DateTime getEnd() {
        return this.end;
    }

    public void setEnd(final DateTime end) {
        this.end = end;
    }

    public boolean isFinished() {
        return this.finished;
    }

    public void setFinished(final boolean finished) {
        this.finished = finished;
    }

    @Override
    public Loan build() {
        return new Loan(this);
    }

    public LoanBuilder withLoanedBook(final Book book) {
        this.loanedBook = book;
        return this;
    }

    public LoanBuilder withLoaner(final Person person) {
        this.loaner = person;
        return this;
    }

    public LoanBuilder withStart(final DateTime date) {
        this.start = date;
        return this;
    }

    public LoanBuilder withEnd(final DateTime date) {
        this.end = date;
        return this;
    }

    public LoanBuilder withFinalization(final boolean bool) {
        this.finished = bool;
        return this;
    }

    @Override
    public Loan example() {
        return new LoanBuilder().withEnd(DateTime.now().plusDays(10)).withLoanedBook(new BookBuilder().example())
                .withLoaner(new PersonBuilder().example()).withStart(DateTime.now()).withFinalization(false).build();
    }
}
